package com.lzb.compressmaster.adapter;

import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lzb.compressmaster.R;
import com.lzb.compressmaster.basic.ProviderMultiAdapter;
import com.lzb.compressmaster.bean.RecentFileBean;

import org.jetbrains.annotations.NotNull;

public class RecentFileAdapter extends ProviderMultiAdapter<RecentFileBean> {

    public RecentFileAdapter() {
        addItemProvider(new PhoneAlbumItemProvider());
    }

    private class PhoneAlbumItemProvider extends BaseItemProvider<RecentFileBean> {
        @Override
        public int getItemViewType() {
            return ProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_recent_file;
        }

        @Override
        public void convert(@NotNull BaseViewHolder baseViewHolder, RecentFileBean bean) {
            baseViewHolder.setText(R.id.tvRecentFileItemDate, bean.getTime());

            if (bean.isSelected()) {
                baseViewHolder.setImageResource(R.id.ivRecentFileItemShow, R.drawable.ahs);
                baseViewHolder.getView(R.id.rvRecentFileChild).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.tvRecentFileItemBottom).setVisibility(View.GONE);
            } else {
                baseViewHolder.setImageResource(R.id.ivRecentFileItemShow, R.drawable.azk);
                baseViewHolder.getView(R.id.rvRecentFileChild).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.tvRecentFileItemBottom).setVisibility(View.VISIBLE);
            }

            RecyclerView rvRecentFileChild = baseViewHolder.getView(R.id.rvRecentFileChild);
            rvRecentFileChild.setLayoutManager(new LinearLayoutManager(getContext()));
            DocumentsAdapter documentsAdapter = new DocumentsAdapter();
            rvRecentFileChild.setAdapter(documentsAdapter);
            documentsAdapter.setList(bean.getMediaInfoList());
            documentsAdapter.setOnItemClickListener(getOnItemClickListener());
        }
    }
}
